<?php
require_once(dirname(__FILE__).'/../../WildPack/WildPack.php');
$wp = new WildPack();
$wp->using('util');
$wp->using('base.wplog');

class TestWpMemLog extends WpTestSuite
{
  
  /**
   * Preparation
   */
  public function prepare() { return true; }
  
  /**
   * Test
   */
  public function test()
  {
        
    $l = new WpMemLog();
    $l->logError('Location', 'Admin', 'Test1', 'Body1', '1', 1);
    $l->logError('Location2', 'Admin', 'Test2', 'Body2', '1', 1);
    $l->logMessage('Location2', 'Admin', 'Message1', 'BodyMessage', '1', 1);
    $l->logAction('Location2', 'Admin', 'Action1', 'BodyAction', '1', 1);
    $l->logAudit('Location2', 'Admin', 'Audit1', 'BodyAudit', '1');
    
    //-- GetNewest --
    $a = $l->grabNewest();
    $this->addResult('Is array', true, is_array($a), '===');
    $this->addResult('Is array', 7, $a, 'count');
    $this->addResult('Has key location', true, array_key_exists('location', $a), '===');
    $this->addResult('Has key date', true, array_key_exists('date', $a), '===');
    $this->addResult('Has key user', true, array_key_exists('user', $a), '===');
    $this->addResult('Has key type', true, array_key_exists('type', $a), '===');
    $this->addResult('Has key title', true, array_key_exists('title', $a), '===');
    $this->addResult('Has key body', true, array_key_exists('body', $a), '===');
    $this->addResult('Has key number', true, array_key_exists('number', $a), '===');
    $this->addResult('Value location', 'Location2', $a['location'], '===');
    $this->addResult('Value user', 'Admin', $a['user'], '===');
    $this->addResult('Value type', 'audit', $a['type'], '===');
    $this->addResult('Value title', 'Audit1', $a['title'], '===');
    $this->addResult('Value body', 'BodyAudit', $a['body'], '===');
    $this->addResult('Value number', '1', $a['number'], '===');
    
    //-- GetOldest --
    $a = $l->grabOldest();
    $this->addResult('Is array', true, is_array($a), '===');
    $this->addResult('Is array', 8, $a, 'count');
    $this->addResult('Has key location', true, array_key_exists('location', $a), '===');
    $this->addResult('Has key date', true, array_key_exists('date', $a), '===');
    $this->addResult('Has key user', true, array_key_exists('user', $a), '===');
    $this->addResult('Has key type', true, array_key_exists('type', $a), '===');
    $this->addResult('Has key title', true, array_key_exists('title', $a), '===');
    $this->addResult('Has key body', true, array_key_exists('body', $a), '===');
    $this->addResult('Has key number', true, array_key_exists('number', $a), '===');
    $this->addResult('Value location', 'Location', $a['location'], '===');
    $this->addResult('Value user', 'Admin', $a['user'], '===');
    $this->addResult('Value type', 'error', $a['type'], '===');
    $this->addResult('Value title', 'Test1', $a['title'], '===');
    $this->addResult('Value body', 'Body1', $a['body'], '===');
    $this->addResult('Value number', '1', $a['number'], '===');
    
    //-- GetNewest --
    $a = $l->grabNewest();
    $this->addResult('Is array', true, is_array($a), '===');
    $this->addResult('Is array', 8, $a, 'count');
    $this->addResult('Has key location', true, array_key_exists('location', $a), '===');
    $this->addResult('Has key date', true, array_key_exists('date', $a), '===');
    $this->addResult('Has key user', true, array_key_exists('user', $a), '===');
    $this->addResult('Has key type', true, array_key_exists('type', $a), '===');
    $this->addResult('Has key title', true, array_key_exists('title', $a), '===');
    $this->addResult('Has key body', true, array_key_exists('body', $a), '===');
    $this->addResult('Has key number', true, array_key_exists('number', $a), '===');
    $this->addResult('Value location', 'Location2', $a['location'], '===');
    $this->addResult('Value user', 'Admin', $a['user'], '===');
    $this->addResult('Value type', 'action', $a['type'], '===');
    $this->addResult('Value title', 'Action1', $a['title'], '===');
    $this->addResult('Value body', 'BodyAction', $a['body'], '===');
    $this->addResult('Value number', '1', $a['number'], '===');
    
    //-- GetOldest --
    $a = $l->grabOldest();
    $this->addResult('Is array', true, is_array($a), '===');
    $this->addResult('Is array', 8, $a, 'count');
    $this->addResult('Has key location', true, array_key_exists('location', $a), '===');
    $this->addResult('Has key date', true, array_key_exists('date', $a), '===');
    $this->addResult('Has key user', true, array_key_exists('user', $a), '===');
    $this->addResult('Has key type', true, array_key_exists('type', $a), '===');
    $this->addResult('Has key title', true, array_key_exists('title', $a), '===');
    $this->addResult('Has key body', true, array_key_exists('body', $a), '===');
    $this->addResult('Has key number', true, array_key_exists('number', $a), '===');
    $this->addResult('Value location', 'Location2', $a['location'], '===');
    $this->addResult('Value user', 'Admin', $a['user'], '===');
    $this->addResult('Value type', 'error', $a['type'], '===');
    $this->addResult('Value title', 'Test2', $a['title'], '===');
    $this->addResult('Value body', 'Body2', $a['body'], '===');
    $this->addResult('Value number', '1', $a['number'], '===');
    
    //-- GetOldest --
    $a = $l->grabOldest();
    $this->addResult('Is array', true, is_array($a), '===');
    $this->addResult('Is array', 8, $a, 'count');
    $this->addResult('Has key location', true, array_key_exists('location', $a), '===');
    $this->addResult('Has key date', true, array_key_exists('date', $a), '===');
    $this->addResult('Has key user', true, array_key_exists('user', $a), '===');
    $this->addResult('Has key type', true, array_key_exists('type', $a), '===');
    $this->addResult('Has key title', true, array_key_exists('title', $a), '===');
    $this->addResult('Has key body', true, array_key_exists('body', $a), '===');
    $this->addResult('Has key number', true, array_key_exists('number', $a), '===');
    $this->addResult('Value location', 'Location2', $a['location'], '===');
    $this->addResult('Value user', 'Admin', $a['user'], '===');
    $this->addResult('Value type', 'message', $a['type'], '===');
    $this->addResult('Value title', 'Message1', $a['title'], '===');
    $this->addResult('Value body', 'BodyMessage', $a['body'], '===');
    $this->addResult('Value number', '1', $a['number'], '===');
    
    //-- Empty
    $a = $l->grabOldest();
    $this->addResult('Is null', true, is_null($a), '===');
  }
  
  /**
   * Cleanup
   */
  public function cleanup() {}
  
  
}

$t = new TestWpMemLog();
$t->start('WpMemLog');
